<?php
class Project extends Zend_Db_Table{
    	protected $_name ="project";
	protected $_primary = 'project_id';

//根据传来的project_id的数组，查询出所有project
    public  function getAllProjectInArray($array,$page,$perpage){

            $where=" project_id in (".implode(',',$array).")";
            $select = $this->select();
            $select->where($where);
            if($page!=9999){
				$select->limitPage($page,$perpage);
			}
            $select->order('create_time desc');
            $sql = $select->__toString();

            return $this->fetchAll($select)->toArray();
    }

    //根据传来的student_id的数组，查询出所有project
    public  function getAllProjectInstudentArray($array){

            $where=" student_id in (".implode(',',$array).")";
            $select = $this->select();
            $select->where($where);
            $select->order('create_time desc');
            $sql = $select->__toString();

            return $this->fetchAll($select)->toArray();
    }
    public function getTopProjects(){
          $select = $this->select();
          $select->limit('10');
          $select->order('project_id desc');
          return $this->fetchAll($select)->toArray();
    }
    // 查询所有项目
    public function getAllProjects($pid,$search_name){
        
          $where = "1=1";
          if($pid=="0"){
              $where.= " and pid=$pid";
          }
          if($search_name!=""){
              $where.= " and title like '%$search_name%'";
          }
          $select = $this->select();
          $select->where($where);

          $select->order('create_time desc');
          return $this->fetchAll($select)->toArray();
    }
    
    public function getAllProjectsexcel(){
        
          $where = "1=1";
          
          $select = $this->select();
          $select->where($where);

          $select->order('create_time asc');
          return $this->fetchAll($select)->toArray();
    }
    
     //根据project_id 查询project
    public function getprojectByproject_id($project_id){
          $select = $this->select();
          $select->where("project_id=".$project_id);
          return $this->fetchAll($select)->toArray();
    }

         //根据teacher_id 查询project
    public function getprojectByteacher_id($teacher_id){
          $select = $this->select();
          $select->where("teacher_id=".$teacher_id);
          return $this->fetchAll($select)->toArray();
    }

     //根据class_id 查询project
    public function getprojectByclass_id($class_id){
          $select = $this->select();
          $select->where("class_id=".$class_id);
          return $this->fetchAll($select)->toArray();
    }

         //根据student_id 查询project
    public function getprojectBystudent_id($student_id){
          $select = $this->select();
          $select->where("student_id=".$student_id);
          return $this->fetchAll($select)->toArray();
    }
    
 //更新project
    public function updateprojectByproject_id($array,$project_id){

		$db = $this->getAdapter();
		$where=$db->quoteInto('project_id = ?', $project_id);
		$this->update($array, $where);
	}
//删除project
     public function delprojectByproject_id($project_id){
          $where = 'project_id = '. $project_id;
         $this->delete($where);
         return true;
    }
	
	public function getProjectByTime($time1, $time2){
		$select = $this->select();
        $select->where("start_time>=".$time1);
		$select->where("start_time<".$time2);
        return $this->fetchAll($select)->toArray();
	}
	
	public function getProjectRelated($arrKeyWords,$page,$perpage){
		if (count($arrKeyWords)!=0) {
			$arrKeyWords = explode(' ', $arrKeyWords[0]);
			
			foreach($arrKeyWords as $key=>$row){
			  if($row!=''){	
				if ($key > 0) {
					$where .= " OR ";
				}
				$where .= " key_word like '$row'";
			   }
			}
			$select = $this->select();
			$select->where($where);
			if($page!=9999){
				$select->limitPage($page,$perpage);
			}
			return $this->fetchAll($select)->toArray();
		}else{
			return array();
		}
	}
	
	public function getProjectByTimeType($time1,$time2,$category){
		$select = $this->select();
		$select->where("category=".$category);
        $select->where("start_time>=".$time1);
		$select->where("start_time<".$time2);
		return $this->fetchAll($select)->toArray();
	}
}
?>
